package com.sinothk.base.version.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sinothk.base.version.domain.entity.AppVersion;
import com.sinothk.base.version.mapper.AppVersionMapper;
import com.sinothk.base.version.service.IAppVersionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 版本信息
 * @Author: Liangyt
 * @Date: 2022-02-17
 * @Version: V1.0
 */
@Service
public class AppVersionServiceImpl extends ServiceImpl<AppVersionMapper, AppVersion> implements IAppVersionService {

    @Override
    public AppVersion queryLatestVersion() throws Exception {
        LambdaQueryWrapper<AppVersion> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AppVersion::getState, 0)
                .orderByDesc(AppVersion::getAppNum);
        List<AppVersion> list = this.list(wrapper);
        if (list != null && list.size() > 0) {
            return list.get(0);
        } else {
            throw new Exception("没有可用版本");
        }
    }
}
